package week3.day20;

import java.io.File;

/**
 * @Author fengzihao
 * @Date 2024-05-04 13:57
 */
public class DeleteDirectory {
    public static void main(String[] args) {
        File file = new File("F:\\testDelete");
        System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath());
        boolean isDelete = deleteDirectory(file);
        System.out.println("isDelete = " + isDelete);
    }

    public static boolean deleteDirectory(File file) {
        File[] files = file.listFiles();
        if (files == null || files.length == 0)
            file.delete();
        else {
            for (int i = 0; i < files.length; i++) {
                deleteDirectory(files[i]);
            }
        }
        file.delete();
        return true;
    }
}
